﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Wicture.DbRESTFul;
using Wicture.DbRESTFul.Rpc.Client;
using Wicture.QPZS.EPC.Repository;

namespace Wicture.QPZS.EPC.Services.UserAuth.Base
{
    public class UserAuthProcessor
    {
        static BaseUserAuthProcessor GetUserAuthProcessor(IDbRESTFulRepository repository)
        {
            BaseUserAuthProcessor userAuthProcesser = new BaseUserAuthProcessor();

            if (repository != null && repository.HttpContext != null)
            {
                string from = repository.HttpContext.Request.Headers["from"];
                switch (from)
                {
                    case "Zpc_Saas":
                        userAuthProcesser = new ZpyUserAuthProcessor();
                        break;
                    default:
                        userAuthProcesser = new EpcUserAuthProcessor();
                        break;
                }
            }
            return userAuthProcesser;
        }

        public static void HandleVinQueryResult(RpcRepository repository, JObject vinInfo)
        {
            GetUserAuthProcessor(repository).HandleVinQueryResult(repository, vinInfo);
        }

        public static void HandlePartListResult(RpcRepository repository, JArray data, string brandCode)
        {
            GetUserAuthProcessor(repository).HandlePartListResult(repository, data, brandCode);
        }
        public static void HandlePartDetailResult(RpcRepository repository, JObject data, string brandCode)
        {
            GetUserAuthProcessor(repository).HandlePartDetailResult(repository, data, brandCode);
        }
        public static void PartListPreProcess(EpcRepository repository, string brandCode)
        {
            GetUserAuthProcessor(repository).PartListPreProcess(repository, brandCode);
        }

        public static void CheckSearchPartTimes(IDbRESTFulRepository repository, string brandCode, string keyword)
        {
            GetUserAuthProcessor(repository).CheckSearchPartTimes(repository, brandCode, keyword);
        }
        public static void CheckSearhPartCounts(IDbRESTFulRepository repository, int times, string brandCode)
        {
            GetUserAuthProcessor(repository).CheckSearhPartCounts(repository, times, brandCode);
        }
        public static void BuildPartSearchResult(IDbRESTFulRepository repository, JObject data)
        {
            GetUserAuthProcessor(repository).BuildPartSearchResult(repository, data);
        }

        public static void HandMaingroupResult(RpcRepository repository, JObject vinInfo)
        {
            GetUserAuthProcessor(repository).HandleMaingroupQueryResult(repository, vinInfo);
        }

    }
}
